package com.example.leetdemo.finash;

import java.util.Arrays;

public class Solution2419 {

    public int longestSubarray(int[] nums) {

        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            max = Math.max(nums[i], max);
        }
        int count = 0;
        int temp = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == max) {
                temp++;
                if (i == nums.length - 1) {
                    count = Math.max(temp, count);
                }
            } else {
                count = Math.max(temp, count);
                temp = 0;
            }
        }
        return count;
    }
}
